package com.java123.sp;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.fastjson.JSONObject;
import com.java123.sp.entity.Student;

public class Work {

	public static void main(String[] args) {
		/**
		 * spring 三大注入方式
		 * 1、注解注入；
		 * 2、setter注入
		 * 3、构造器注入
		 */
		ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring.xml");
		//spring容器已启动
		//通过id获取
		Student stu = (Student) context.getBean("student");
		//打印
		System.out.println(JSONObject.toJSONString(stu));
		//通过类型获取
		//Student s = context.getBean(Student.class);
		Student s1 = (Student) context.getBean("s1");
		System.out.println(JSONObject.toJSONString(s1));
		System.out.println(stu == s1);
		//spring使用的是 单例模式
		//System.out.println(s == stu);
	}

}
